//
//  PeopleProjectViewController.m
//  Qihuo
//
//  Created by Cheng Qi on 13-12-10.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "PeopleProjectViewController.h"
#import "PeopleProjectMode.h"
@interface PeopleProjectViewController ()

@end

@implementation PeopleProjectViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark--UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    [super tableView:tableView numberOfRowsInSection:section];
    if (tableView==self.myTableView) {
        return [self.allShowDataArr count];
    }else
        return 0;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView  cellForRowAtIndexPath:indexPath];
    
    if (tableView==self.myTableView) {
        self.mycell.textLabel.text =[self.allShowDataArr objectAtIndex:indexPath.row];
        return self.mycell;
    }else
        return nil;
    
}

-(void)jajajajaj:(UIButton *)btn
{
    switch (btn.tag) {
        case 0:
        {
            NSLog(@"%@",@"提交");
            [self sendCheck];
            //[self loginSendData];
        }
            break;
            
        default:
            break;
    }
}

- (void)sendCheck
{
    NSMutableArray * dataArr = [[NSMutableArray alloc]init];
    for (int i = 0; i < peopleModeArr.count; i++) {
        PeopleProjectMode * modeView = (PeopleProjectMode *)[peopleModeArr objectAtIndex:i];
        NSString * checkId = [NSString stringWithFormat:@"%d",modeView.tag + 1];
        NSString * isNormal = [NSString stringWithFormat:@"%d",modeView.stateFlag];
        NSString * result = [modeView.checkTV.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString * checkRemark = [modeView.remarks.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:checkId, @"checkId",
                              isNormal,@"isNormal",
                              result,@"result",
                              checkRemark,@"checkRemark",
                              nil];
        [dataArr addObject:dic];
    }
    UITextField *remarkTv = (UITextField *)[self.blackStopV viewWithTag:290];
    NSDictionary * final = [NSDictionary dictionaryWithObjectsAndKeys:
                            [[Appinfomation shareIstance].loginDic objectForKey:@"id"],@"userId",
                            dataArr,@"checkData",[self.checkArea stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],@"checkArea",remarkTv.text,@"abolishRemark",@"0",@"isAbolished",
                                     nil];
    self.sendAllDic.dictionary = final;
    self.sendUrl = sendPeopleProject;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    //self.sendAllDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:self.sendFloorDatas,@"floorData",[[Appinfomation shareIstance].loginDic valueForKey:@"id"],@"userId", nil];
    NSLog(@"%@",self.sendAllDic);
    NSString *str1 =[self.sendAllDic JSONRepresentation];
    NSURL *sendUrl = [NSURL URLWithString:self.sendUrl];
    peopleProject = [ASIFormDataRequest requestWithURL:sendUrl];
    peopleProject.delegate=self;
    [peopleProject setPostValue:str1 forKey:@"data"];
    [peopleProject startAsynchronous];
    [peopleProject setDidFinishSelector:@selector(showAlertSuccess)];
    [peopleProject setDidFinishSelector:@selector(showAlertFail)];
}

#pragma mark-Resource


-(void)changeTableView
{
    UILabel *label1 =[[UILabel alloc]initWithFrame:CGRectMake(0,10,100, 60)];
    label1.text=@"天气:";
    UIImage *blackImage = [UIImage imageNamed:@"黑底"];
    self.myTableView.frame=CGRectMake(interval111/2, 64, 0, screenHeight - blackImage.size.height - 64);
    self.whiteImageView.frame=CGRectMake(self.myTableView.frame.origin.x + self.myTableView.frame.size.width, self.myTableView.frame.origin.y, scrennWidth - (self.myTableView.frame.origin.x)*2 -self.myTableView.frame.size.width, self.myTableView.frame.size.height);
    self.backScrollV.frame =CGRectMake(10, 10, self.whiteImageView.frame.size.width - 20, self.whiteImageView.frame.size.height - 20);
}

- (void)addDetailUI
{
    peopleModeArr = [[NSMutableArray alloc]init];
    checkArr = [[NSArray alloc]initWithObjects:@"防护密闭",@"防爆波活门",@"密封胶条",@"脚踏送风机",@"手动密闭阀",@"自动排气活门",@"通风机",@"钢制风管",@"集水井",@"排污水泵",@"电器线路",@"照明设备",@"进风/排风扩散室", nil];
    for (int i = 0; i < checkArr.count; i++) {
        PeopleProjectMode * peopleMode = [[[PeopleProjectMode alloc]initWithFrame:CGRectMake(0, i * 500 + 10, self.whiteImageView.frame.size.width - 20, 500)]autorelease];
        peopleMode.mainTitle.text = [checkArr objectAtIndex:i];
        peopleMode.tag = i;
        [self.backScrollV addSubview:peopleMode];
        [peopleModeArr addObject:peopleMode];
    }
    
    self.backScrollV.contentSize = CGSizeMake(0, 500 * checkArr.count + 10 * (checkArr.count + 1));
    
}

- (void) keyboardWasShown:(NSNotification *) notif
{
//    NSDictionary *info = [notif userInfo];
//    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
//    keyboardSize = [value CGRectValue].size;
//    NSLog(@"keyBoard:%f", keyboardSize.width);  //406
//    _backScrollV.contentSize = CGSizeMake(_backScrollV.frame.size.width, _commentTv.frame.origin.y + _commentTv.frame.size.height + interval111+406);
//    if (blackGroundV.hidden == NO)
//    {
//        [UIView animateWithDuration:.5 animations:^{
//            blackGroundV.frame = CGRectMake(0, -150, 1024, 768);
//        }];
//    }
//    if (blackStopV.hidden == NO) {
//        [UIView animateWithDuration:.5 animations:^{
//            blackStopV.frame = CGRectMake(0, -150, 1024, 768);
//        }];
//    }
}
- (void) keyboardWasHidden:(NSNotification *) notif
{
//    NSDictionary *info = [notif userInfo];
//    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
//    CGSize keyboardSize = [value CGRectValue].size;
//    NSLog(@"keyboardWasHidden keyBoard:%f", keyboardSize.width);
//    _backScrollV.contentSize = CGSizeMake(_backScrollV.frame.size.width, _commentTv.frame.origin.y + _commentTv.frame.size.height + interval111);
//    if (blackGroundV.hidden == NO)
//    {
//        [UIView animateWithDuration:0.5 animations:^{
//            blackGroundV.frame = CGRectMake(0, 0, 1024, 768);
//        }];
//    }
//    if (blackStopV.hidden == NO) {
//        [UIView animateWithDuration:.5 animations:^{
//            blackStopV.frame = CGRectMake(0, 0, 1024, 768);
//        }];
//    }
}

- (void)viewDidLoad
{
    self.title =@"人防工程设备巡检";
    [super viewDidLoad];
    [self changeTableView];
    [self addDetailUI];
    UIButton *btn = (UIButton *)[self.blackView viewWithTag:0];
    [btn setImage:[UIImage imageNamed:@"提交"] forState:UIControlStateNormal];
    //[self addDataArray];
    // Do any additional setup after loading the view from its nib.
}

- (void)dealloc
{
    [super dealloc];
    [peopleModeArr removeAllObjects];
    [peopleModeArr release];
    peopleModeArr = Nil;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
